﻿@using HP.HPTRIM.Web.Configuration;
@using HP.HPTRIM.ServiceModel;
@using HP.HPTRIM.Service;
@using System.Linq;
@using HP.HPTRIM.WebDrawer;
@inherits TrimViewPage<RecordsResponse>
@{

    if (@HttpContext.Current.Request.QueryString["q"] == null) {
		ViewBag.SearchHelp = Translations.lang.record_search_help;
    }    
	
}

@Html.Partial("searchBanner")

<form class="search-form" action="~/Images" method="GET">
    <div class="input-append" style="text-align:center">
        <input type="text" name="q" autocomplete="off" style="width:400px;" />
        <button class="btn nowrap" type="submit">@Translations.lang.quick_search</button>
    </div>
</form>
 
<ul class="thumbnails" style="margin-left:20px;">
@foreach (Record record in Model.Results)
{
    <li class="span2">
        <div class="thumbnail">
            <a href="~/RecordHtml/@record.Uri">
                <img src="~/thumbnail/@record.Uri" alt="">
                <h5>@record.Title</h5>
            </a>
        </div>
    </li>
}
</ul>

@{
    int pageSize = ServiceDefaults.Instance.RouteDefaults["imagesrecords"].pageSize;

    if (!Int32.TryParse(HttpContext.Current.Request.QueryString["pageSize"], out pageSize))
    {
        pageSize = ServiceDefaults.Instance.RouteDefaults["imagesrecords"].pageSize;
    }
        
    int start = 0;
    Int32.TryParse(HttpContext.Current.Request.QueryString["start"], out start);

    var queryString = new System.Collections.Specialized.NameValueCollection(HttpContext.Current.Request.QueryString);

    <div class="pagination pagination-centered">
        <ul id="trim-pagination">
            <li class="@(start < 2 ? "disabled" : null)">
                @{
                    queryString["start"] = (start > pageSize ? start - pageSize : 0).ToString();
                    <a href="?@queryString.ToFormUrlEncoded()">&laquo;</a>
                }
            </li>

            <li class="@(!this.Model.HasMoreItems ? "disabled" : null)">
                @if (this.Model.HasMoreItems)
                {
                    start = (start == 0 ? start + 1 : start);
                    queryString["start"] = (start + pageSize).ToString();
                    <a href="?@queryString.ToFormUrlEncoded()">&raquo;</a>
                }
                else
                {
                    <span>&raquo;</span>
                }
            </li>
        </ul>
    </div>
}